import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { isArray } from '/@/utils/is';
export const columns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'name',
  },
  {
    title: '标题栏',
    dataIndex: 'barName',
  },
  {
    title: '表头字体',
    dataIndex: 'fontFamily',
  },
  {
    title: '表头字号',
    dataIndex: 'fontSize',
  },
  {
    title: '表头背景色',
    dataIndex: 'backColor',
    customRender: ({ text }) => {
      return h('div', {
        style: `border: 1px solid rgb(204, 204, 204); border-image: none; width: 16px; height: 16px; vertical-align: middle; display: inline-block; background-color: ${text};`,
      });
    },
  },
  {
    title: '表头前景色',
    dataIndex: 'foreColor',
    customRender: ({ text }) => {
      return h('div', {
        style: `border: 1px solid rgb(204, 204, 204); border-image: none; width: 16px; height: 16px; vertical-align: middle; display: inline-block; background-color: ${text};`,
      });
    },
  },
  {
    title: '表头加粗',
    dataIndex: 'isBold',
    customRender: ({ text }) => {
      return text == 1 ? '是' : '否';
    },
  },
  {
    title: '行高',
    dataIndex: 'lineHeight',
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '名称',
    required: true,
    component: 'Input',
    slot: 'name',
    colProps: {
      span: 24,
    },
  },
  {
    field: 'barName',
    label: '标题栏文字',
    helpMessage: '空表示无标题栏',
    component: 'Input',
    colProps: {
      span: 24,
    },
  },
  {
    field: 'barFontFamily',
    label: '标题栏格式',
    required: true,
    component: 'Input',
    slot: 'barFontFamily',
    colProps: {
      span: 24,
    },
  },
  {
    field: 'fontFamily',
    label: '表头',
    required: true,
    component: 'Input',
    slot: 'fontFamily',
    colProps: {
      span: 24,
    },
  },
  {
    field: 'role',
    label: '角色',
    helpMessage: '为空则表示角色不限，均可以使用此模板',
    component: 'Input',
    slot: 'role',
    colProps: {
      span: 24,
    },
  },
];

export const barFontFamily = [
  {
    label: '微软雅黑',
    value: '微软雅黑',
  },
  {
    label: '黑体',
    value: '黑体',
  },
  {
    label: '宋体',
    value: '宋体',
  },
  {
    label: '仿宋体',
    value: '仿宋体',
  },
];

// /createExportTemplate
// name: 测试
// is_serial_no: 1
// bar_name: 标题栏文字
// bar_font_family: 微软雅黑
// bar_font_size: 12
// bar_line_height: 30
// bar_back_color: #00FF00
// bar_fore_color: #662B2B
// bar_is_bold: 1
// font_family: 微软雅黑
// font_size: 12
// line_height: 30
// back_color: #002B81
// fore_color: #000000
// is_bold: 1
// roleDescs: 归档人,副校长
// roleCodes: gd,fxz
// moduleCode: personbasic
// cols: [{"field":"realname","name":"realname","width":87,"link":"&","title":"姓名"},{"field":"sex","name":"sex","width":76,"link":"#","title":"性别"},{"field":"user_name","name":"user_name","width":80,"link":"#","title":"登录帐户"},{"field":"dept","name":"dept","width":316,"link":"#","title":"部门"},{"field":"email","name":"email","width":104,"link":"#","title":"Email"},{"field":"zgxl","name":"zgxl","width":126,"link":"#","title":"最高学历"},{"field":"age","name":"age","width":52,"link":"#","title":"年龄"},{"field":"mobile","name":"mobile","width":146,"link":"#","title":"手机"},{"field":"csrq","name":"csrq","width":122,"link":"#","title":"出生日期"},{"field":"whcd","name":"whcd","width":123,"link":"#","title":"文化程度"},{"field":"people","name":"people","width":93,"link":"#","title":"民族"},{"field":"address","name":"address","width":196,"link":"#","title":"家庭地址"},{"field":"entry_date","name":"entry_date","width":148,"link":"#","title":"入职时间"},{"field":"jiguan","name":"jiguan","width":148,"link":"#","title":"籍贯"},{"field":"chushengdi","name":"chushengdi","width":148,"link":"#","title":"出生地"},{"field":"pos","name":"pos","width":148,"link":"#","title":"岗位"},{"field":"zzmm","name":"zzmm","width":150,"link":"#","title":"政治面貌"},{"field":"formal_date","name":"formal_date","width":150,"link":"#","title":"转正日期"}]
// formCode: personbasic

// /updateExportTemplate
// name: 测试1
// is_serial_no: 1
// bar_name: 标题栏文字
// bar_font_family: 微软雅黑
// bar_font_size: 12
// bar_line_height: 30
// bar_back_color: #00FF00
// bar_fore_color: #662B2B
// bar_is_bold: 1
// font_family: 微软雅黑
// font_size: 12
// line_height: 30
// back_color: #002B81
// fore_color: #000000
// is_bold: 1
// roleDescs: 归档人,副校长
// roleCodes: gd,fxz
// id: 1
// code: personbasic
// formCode: personbasic
// cols: [{"field":"realname","name":"realname","width":87,"link":"
// ","title":"姓名"},{"field":"sex","name":"sex","width":76,"link":"#","title":"性别"},{"field":"user_name","name":"user_name","width":80,"link":"#","title":"登录帐户"},{"field":"dept","name":"dept","width":316,"link":"#","title":"部门"},{"field":"email","name":"email","width":104,"link":"#","title":"Email"},{"field":"zgxl","name":"zgxl","width":126,"link":"#","title":"最高学历"},{"field":"age","name":"age","width":52,"link":"#","title":"年龄"},{"field":"mobile","name":"mobile","width":146,"link":"#","title":"手机"},{"field":"csrq","name":"csrq","width":122,"link":"#","title":"出生日期"},{"field":"whcd","name":"whcd","width":123,"link":"#","title":"文化程度"},{"field":"people","name":"people","width":93,"link":"#","title":"民族"},{"field":"address","name":"address","width":196,"link":"#","title":"家庭地址"},{"field":"entry_date","name":"entry_date","width":148,"link":"#","title":"入职时间"},{"field":"jiguan","name":"jiguan","width":148,"link":"#","title":"籍贯"},{"field":"chushengdi","name":"chushengdi","width":148,"link":"#","title":"出生地"},{"field":"pos","name":"pos","width":148,"link":"#","title":"岗位"},{"field":"zzmm","name":"zzmm","width":150,"link":"#","title":"政治面貌"},{"field":"formal_date","name":"formal_date","width":150,"link":"#","title":"转正日期"}]:

export const setData = (record, isUpdate) => {
  let list = [];
  if (isArray(record.cols) && record.cols.length) {
    list = record.cols.map((item) => {
      return {
        field: item.field,
        name: item.field,
        width: item.width,
        link: item.link || '#',
        title: item.title,
      };
    });
  }
  const data: Recordable = {
    id: record.id,
    name: record.name,
    is_serial_no: record.isSerialNo ? 1 : 0,
    bar_name: record.barName,
    bar_font_family: record.barFontFamily,
    bar_font_size: record.barFontSize,
    bar_line_height: record.barLineHeight,
    bar_back_color: record.barBackColor,
    bar_fore_color: record.barForeColor,
    bar_is_bold: record.barIsBold ? 1 : 0,
    font_family: record.fontFamily,
    font_size: record.fontSize,
    line_height: record.lineHeight,
    back_color: record.backColor,
    fore_color: record.foreColor,
    is_bold: record.isBold ? 1 : 0,
    roleDescs: record.roleDescs,
    roleCodes: record.roleCodes,
    cols: list.length ? JSON.stringify(list) : '',
  };
  if (!isUpdate) {
    data.moduleCode = record.moduleCode;
    data.formCode = record.formCode;
  } else {
    data.code = record.moduleCode;
    data.formCode = record.formCode;
  }
  for (const v in data) {
    if (data[v] === undefined || data[v] === null) {
      data[v] = '';
    }
  }
  if (data.is_serial_no == 0) {
    delete data.is_serial_no;
  }
  if (data.bar_is_bold == 0) {
    delete data.bar_is_bold;
  }
  if (data.is_bold == 0) {
    delete data.is_bold;
  }
  return data;
};
